/**
* Copyright (C) 2018-2020
* All rights reserved, Designed By www.yixiang.co
* 注意：
* 本软件为www.yixiang.co开发研制，未经购买不得使用
* 购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
* 一经发现盗用、分享等行为，将追究法律责任，后果自负
*/
package co.yixiang.modules.product.rest;

import co.yixiang.domain.PageResult;
import co.yixiang.dozer.service.IGenerator;
import co.yixiang.logging.aop.log.Log;
import co.yixiang.modules.product.domain.YxTestQuestionDetail;
import co.yixiang.modules.product.service.YxTestQuestionDetailService;
import co.yixiang.modules.product.service.dto.YxTestQuestionDetailDto;
import co.yixiang.modules.product.service.dto.YxTestQuestionDetailQueryCriteria;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
* @author lsh
* @date 2021-07-20
*/
@AllArgsConstructor
@Api(tags = "YxTestQuestionDetail管理")
@RestController
@RequestMapping("/api")
public class YxTestQuestionDetailController {

    private final YxTestQuestionDetailService yxTestQuestionDetailService;
    private final IGenerator generator;


    @Log("导出数据")
    @ApiOperation("导出数据")
    @GetMapping(value = "/yxTestQuestionDetail/download")
    @PreAuthorize("@el.check('admin','yxTestQuestionDetail:list')")
    public void download(HttpServletResponse response, YxTestQuestionDetailQueryCriteria criteria) throws IOException {
        yxTestQuestionDetailService.download(generator.convert(yxTestQuestionDetailService.queryAll(criteria), YxTestQuestionDetailDto.class), response);
    }

    @GetMapping(value = "/yxTestQuestionDetail")
    @Log("查询YxTestQuestionDetail")
    @ApiOperation("查询YxTestQuestionDetail")
    @PreAuthorize("hasAnyRole('admin','YXTESTQUESTIONDETAIL_ALL','YXTESTQUESTIONDETAIL_SELECT')")
    public ResponseEntity<PageResult<YxTestQuestionDetailDto>> getYxTestQuestionDetails(YxTestQuestionDetailQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(yxTestQuestionDetailService.queryAll(criteria,pageable),HttpStatus.OK);
    }


    @PostMapping(value = "/yxTestQuestionDetail")
    @Log("新增YxTestQuestionDetail")
    @ApiOperation("新增YxTestQuestionDetail")
    @PreAuthorize("hasAnyRole('admin','YXTESTQUESTIONDETAIL_ALL','YXTESTQUESTIONDETAIL_CREATE')")
    public ResponseEntity<Object> create(@Validated @RequestBody YxTestQuestionDetail resources){
        return new ResponseEntity<>(yxTestQuestionDetailService.save(resources),HttpStatus.CREATED);
    }

    @PutMapping(value = "/yxTestQuestionDetail")
    @Log("修改YxTestQuestionDetail")
    @ApiOperation("修改YxTestQuestionDetail")
    @PreAuthorize("hasAnyRole('admin','YXTESTQUESTIONDETAIL_ALL','YXTESTQUESTIONDETAIL_EDIT')")
    public ResponseEntity<Object> update(@Validated @RequestBody YxTestQuestionDetail resources){
        yxTestQuestionDetailService.updateById(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @Log("删除YxTestQuestionDetail")
    @ApiOperation("删除YxTestQuestionDetail")
    @PreAuthorize("hasAnyRole('admin','YXTESTQUESTIONDETAIL_ALL','YXTESTQUESTIONDETAIL_DELETE')")
    @DeleteMapping(value = "/yxTestQuestionDetail/{id}")
    public ResponseEntity<Object> deleteAll(@PathVariable Long id) {
            yxTestQuestionDetailService.removeById(id);
        return new ResponseEntity<>(HttpStatus.OK);
    }
}
